
<h2 style='text-align:center'>商品审核</h2>


<div id='MainGoods_GoodsListArea'>
	<div style='display:flex'>
		<div style='flex:1'>
			<input type="text" id='MainGoods_SearchInp' style='width:100%' />
		</div>
		<div>
			<button type='button' id='MainGoods_SearchBtn'>搜索</button>
		</div>
	</div>
	<select id="MainGoods_TypeSelect" style='width:100%'>
		<option value="all">全部</option>
		<option value="1">待审核</option>
		<option value="2">正常</option>
		<option value="3">未通过</option>
		<option value="4">已封禁</option>
		<option value="5">已下架</option>
	</select>


	<!--商品列表-->
	<div id='MainGoods_GoodsList'></div>


	<!--分页-->
	<div id='MainGoods_GoodsFpage' style='text-align:center;margin:20px auto'></div>

	<div>
		<button id='MainGoods_Back'>返回商户管理</button>
	</div>
</div>


<!--商品详情-->
<div id='MainGoods_GoodsDetail'></div>

<script>
var detail_id = ''; 	//指定的商品详情id

//判断是否为商户页跳转而来
if(sessionStorage.StoreToGoods_StoreId){
	$('#MainGoods_Back').show();
	var store_id = sessionStorage.StoreToGoods_StoreId;
}else{
	$('#MainGoods_Back').hide();
	var store_id = 0;
}

//当前页
if(!sessionStorage.MainGoods_Pnow){
	sessionStorage.MainGoods_Pnow = 1;
}

//最大页
if(!sessionStorage.MainGoods_MaxPage){
	sessionStorage.MainGoods_MaxPage = 2;
}

//初始始化商品搜索值
if(!sessionStorage.MainGoods_Search){
	sessionStorage.MainGoods_Search = '';
}else{
	$('#MainGoods_SearchInp').val(ChangeChar(sessionStorage.MainGoods_Search,1));
}

//状态维持
if(sessionStorage.MainGoods_statType){
	$('#MainGoods_TypeSelect').val(sessionStorage.MainGoods_statType);
}

$('#MainGoods_SearchBtn').click(function(){
	sessionStorage.MainGoods_Search = ChangeChar($('#MainGoods_SearchInp').val().trim());
	_MainGoods_Reset(); 	//重置商品列表面的当前页和最大页的值
	MainGoods_GetGoodsList();	//获取商品列表
});



//切换商品状态
$('#MainGoods_TypeSelect').change(function(){
	sessionStorage.MainGoods_statType = $('#MainGoods_TypeSelect').find('option:selected').val();
	_MainGoods_Reset(); 	//重置商品列表面的当前页和最大页的值
	MainGoods_GetGoodsList();	//获取商品列表
});




//获取商品列表
function MainGoods_GetGoodsList(){


	var data = {
		type:'getGoodsListFull',
		pnow:sessionStorage.MainGoods_Pnow,
		search:sessionStorage.MainGoods_Search,
		type_sel:sessionStorage.MainGoods_statType,
		store_id:store_id
	};
	AjaxAdmin(data,function(res){
		var tmp = _checkJsonFormat(res);
	 	MainGoods_GetGoodsListParse(tmp.data);
	});
}
	
MainGoods_GetGoodsList();	//获取商品列表



//刷新数据
$('#MainGoods_Refresh').click(function(){
	MainGoods_GetGoodsList();
});



//返回商户审核页
$('#MainGoods_Back').click(function(){
	_MainGoods_Reset(1);
	$('#Main_Nav').val('Main_Store');
	_loadPage();
});



//解析列表
function MainGoods_GetGoodsListParse(tmp_data){
	if(typeof(tmp_data) == 'object' && tmp_data.length > 0){
		var tmp_str = '';
		for(var i=0;i<tmp_data.length;i++){
			var imgAddr = upyun_shop_img + tmp_data[i].banner;
			tmp_str += "<div style='border:1px solid #ccc;display:flex;margin:5px 0;'><div style='width:100px'><img src='"+imgAddr+"' style='width:100px;height:100px'/></div>";
			tmp_str += "<div style='flex:1'><div style='word-break:break-all;font-size:14px;color:#777;padding:5px'>";
			tmp_str += "商品标题："+ChangeChar(tmp_data[i].title,2);
			tmp_str += "<br>价格："+tmp_data[i].price+'元';
			switch(tmp_data[i].goods_stat){
				case '1':var stat_str2 = '<span style="color:#fff">待审</span>';break;
				case '2':var stat_str2 = '<span style="color:blue">正常</span>';break;
				case '3':var stat_str2 = '<span style="color:yellow">未通过</span>';break;
				case '4':var stat_str2 = '<span style="color:red">已封禁</span>';break;
				case '5':var stat_str2 = '<span style="color:#444">已下架</span>';break;
			}
			tmp_str += "<br><span>类型："+tmp_data[i].type_set+"</span>";
			tmp_str +="<br><span style='text-align:right'>状态："+stat_str2+"</span>";

			tmp_str +="<div style='text-align:right'><button  onclick=MainGoods_GoodsDetail("+tmp_data[i].id+")>查看详情</button>　<!--button onclick=MainGoods_ChangeGoodsStat("+tmp_data[i].id+",2)>通过</button><button onclick=MainGoods_ChangeGoodsStat("+tmp_data[i].id+",3)>未通过</button><button onclick=MainGoods_ChangeGoodsStat("+tmp_data[i].id+",4)>封禁</button><button onclick=MainGoods_ChangeGoodsStat("+tmp_data[i].id+",1)>解封</button--></div>";

			tmp_str += "<div style='clear:both'></div></div></div></div>";
		}
		$('#MainGoods_GoodsList').html(tmp_str);
		Fpage(sessionStorage.MainGoods_Pnow,sessionStorage.MainGoods_MaxPage,function(p){
			sessionStorage.MainGoods_Pnow = p;
			sessionStorage.MainGoods_MaxPage = p+1;
			MainGoods_GetGoodsList();
		},1,1,'#MainGoods_GoodsFpage');
	}else{
		if(sessionStorage.MainGoods_Pnow == 1){
			$('#MainGoods_GoodsList').html('<h2 style="text-align:center;color:red">暂无数据</h2>');
			Fpage(1,1,function(p){
				
			},1,1,'#MainGoods_GoodsFpage');
		}else{
			sessionStorage.MainGoods_Pnow = sessionStorage.MainGoods_Pnow>2?sessionStorage.MainGoods_Pnow-1:1;
			sessionStorage.MainGoods_MaxPage = sessionStorage.MainGoods_Pnow;
			MainGoods_GetGoodsList();

		}
	}
}


//查看商品详情
function MainGoods_GoodsDetail(id){
	detail_id = id;
	$('#MainGoods_GoodsListArea').hide();
	Ajax('',function(res){
		$('#MainGoods_GoodsDetail').html(res).show();
	},'Template/Main_Goods_GoodsDetail.html');
}



//修改商品状态
function MainGoods_ChangeGoodsStat(id,stat){
	Notice('处理中......');
	var data = {
		type:'changeGoodsStat',
		id:id,
		stat:stat
	}
	AjaxAdmin(data,function(res){
		Notice();
		var tmp = _checkJsonFormat(res);
		if(tmp.stat == 'ok'){
			A('操作成功！');
			//location.reload();
			MainGoods_GetGoodsList();	//获取商品列表
		}else{
			A('操作异常！');
		}
	});

}


//重置本页相关数据
function _MainGoods_Reset(type){
	sessionStorage.MainGoods_MaxPage = 2;
	sessionStorage.MainGoods_Pnow = 1;
	if(type){
		sessionStorage.MainGoods_Search = '';
		sessionStorage.MainGoods_statType = '';
		sessionStorage.StoreToGoods_StoreId = '';
	}
}


</script>